package fr.afcepf.ai89.esharing.tests;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import fr.afcepf.ai89.esharing.data.IDAOAem;
import fr.afcepf.ai89.esharing.data.IDAOMessagePrive;
import fr.afcepf.ai89.esharing.entity.Aem;
import fr.afcepf.ai89.esharing.entity.ImgAem;
import fr.afcepf.ai89.esharing.entity.Indisponibilite;
import fr.afcepf.ai89.esharing.entity.InvisibiliteAem;
import fr.afcepf.ai89.esharing.entity.Marque;
import fr.afcepf.ai89.esharing.entity.PromotionAem;
import fr.afcepf.ai89.esharing.entity.PromotionParc;
import fr.afcepf.ai89.esharing.entity.Proprietaire;
import fr.afcepf.ai89.esharing.entity.TypeAem;
import fr.afcepf.ai89.esharing.entity.Valeur;
import fr.afcepf.ai89.esharing.metier.BusinessGestionParcAem;
import fr.afcepf.ai89.esharing.metier.IBusinessGestionParcAem;

public class BusinessGestionParcAemTest {

	IBusinessGestionParcAem bgpa = new BusinessGestionParcAem();

	public static void main(String[] args) {
		BusinessGestionParcAemTest bgpat = new BusinessGestionParcAemTest();
		// bgpat.testAddAem();
		// bgpat.testMajAem();
		// bgpat.testRetirerAem();
		// bgpat.testAddIndispo();
		// bgpat.testMajIndispo();
		// bgpat.testRetirerIndispo();
		// bgpat.testAddInvisAem();
		// bgpat.testMajInvisAem();
		// bgpat.testRetirerInvisAem();
		// bgpat.testAddImgAem();
		// bgpat.testMajImgAem();
		// bgpat.testChangerValeur();
		// bgpat.testGetPromosAem();
		// bgpat.testPromouvoirAem();
		// bgpat.testMajPromoAem();
		// bgpat.testGetPromoParc();
		// bgpat.testPromouvoirParc();
		bgpat.testMajPromoParc();
	}

	public void testAddAem() {
		Aem aem = new Aem();
		Marque m = new Marque();
		m.setIdMarque(1);
		Proprietaire p = new Proprietaire();
		p.setIdUtilisateur(1);
		TypeAem t = new TypeAem();
		t.setIdTypeAem(1);

		aem.setMarque(m);
		aem.setProprietaire(p);
		aem.setTypeAem(t);
		aem.setDateAjout(new Date());
		aem.setDescAem("test ajout aem");

		bgpa.addAem(aem);
	}

	public void testMajAem() {
		Aem aem = new Aem();
		aem.setIdAem(32);
		aem.setDateRevocation(new Date());
		aem.setDateAjout(new Date());
		Marque m = new Marque();
		m.setIdMarque(1);
		aem.setMarque(m);
		Proprietaire p = new Proprietaire();
		p.setIdUtilisateur(1);
		aem.setProprietaire(p);
		TypeAem t = new TypeAem();
		t.setIdTypeAem(1);
		aem.setTypeAem(t);
		bgpa.majAem(aem);
	}

	public void testRetirerAem() {
		Aem aem = new Aem();
		aem.setIdAem(32);
		bgpa.retirerAem(aem);
	}

	public void testAddIndispo() {
		Indisponibilite indispo = new Indisponibilite();
		Date d = new Date();
		indispo.setDateDebutIndisponibiliteAem(d);
		indispo.setDateFinIndisponibiliteAem(d);
		Aem aem = new Aem();
		aem.setIdAem(32);
		indispo.setAem(aem);
		bgpa.addIndispo(indispo);
	}

	public void testMajIndispo() {
		Indisponibilite indispo = new Indisponibilite();
		indispo.setIdIndisponibiliteAem(2);
		Aem aem = new Aem();
		aem.setIdAem(30);
		indispo.setAem(aem);
		indispo.setDateDebutIndisponibiliteAem(new Date());
		indispo.setDateFinIndisponibiliteAem(new Date());
		bgpa.majIndispo(indispo);
	}

	public void testRetirerIndispo() {
		Indisponibilite indispo = new Indisponibilite();
		indispo.setIdIndisponibiliteAem(2);
		bgpa.retirerIndispo(indispo);
	}

	public void testAddInvisAem() {
		InvisibiliteAem invis = new InvisibiliteAem();
		Aem aem = new Aem();
		aem.setIdAem(32);
		invis.setAem(aem);
		invis.setDebutInvisibiliteAem(new Date());
		invis.setFinInvisibiliteAem(new Date());
		bgpa.addInvisAem(invis);
	}

	public void testMajInvisAem() {
		InvisibiliteAem invis = new InvisibiliteAem();
		Aem aem = new Aem();
		aem.setIdAem(30);
		invis.setAem(aem);
		invis.setDebutInvisibiliteAem(new Date());
		invis.setFinInvisibiliteAem(new Date());

		invis.setIdInvisibiliteAem(2);
		bgpa.majInvisAem(invis);
	}

	public void testRetirerInvisAem() {
		InvisibiliteAem invis = new InvisibiliteAem();
		invis.setIdInvisibiliteAem(2);
		bgpa.retirerInvisAem(invis);
	}

	public void testAddImgAem() {
		ImgAem img = new ImgAem();
		Aem aem = new Aem();
		aem.setIdAem(32);
		img.setAem(aem);
		img.setLienImgAem("C:/images/image.jpg");
		bgpa.addImgAem(img);
	}

	public void testMajImgAem() {
		ImgAem img = new ImgAem();
		img.setIdImgAem(1);
		Aem aem = new Aem();
		aem.setIdAem(32);
		img.setAem(aem);
		img.setLienImgAem("C:/images/image2.jpg");
		bgpa.majImgAem(img);
	}

	public void testChangerValeur() {
		Valeur val = new Valeur();
		Aem aem = new Aem();
		aem.setIdAem(32);
		val.setAem(aem);
		val.setDateActualisationValeur(new Date());
		val.setValeurJournaliere(new BigDecimal("9999"));
		bgpa.changerValeur(val);
	}

	public void testGetPromosAem() {
		Aem aem = new Aem();
		aem.setIdAem(32);
		List<PromotionAem> promos = (List<PromotionAem>) bgpa.getPromosAem(aem);
		for (PromotionAem promo : promos) {
			System.out.println(promo.getNomPromotionAem() + " "
					+ promo.getRaisonPromotionAem() + " "
					+ promo.getAem().getTypeAem().getTypeAem() + " "
					+ promo.getAem().getMarque().getMarque() + " "
					+ promo.getDateDebutPromotionAem() + " "
					+ promo.getDateFinPromotionAem() + " "
					+ promo.getPourcentReducAem());
		}
	}

	public void testPromouvoirAem() {
		PromotionAem promoAem = new PromotionAem();
		Aem aem = new Aem();
		aem.setIdAem(32);
		promoAem.setAem(aem);
		promoAem.setDateDebutPromotionAem(new Date());
		promoAem.setDateFinPromotionAem(new Date());
		promoAem.setNomPromotionAem("La grosse promo");
		promoAem.setPourcentReducAem(new BigDecimal(0.10));
		promoAem.setRaisonPromotionAem("Parce que c'�tait trop cher");
		bgpa.promouvoirAem(promoAem);
	}

	public void testMajPromoAem() {
		PromotionAem promoAem = new PromotionAem();
		promoAem.setIdPromotionAem(2);
		Aem aem = new Aem();
		aem.setIdAem(32);
		promoAem.setAem(aem);
		promoAem.setDateDebutPromotionAem(new Date());
		promoAem.setDateFinPromotionAem(new Date());
		promoAem.setNomPromotionAem("Une promotion encore plus sympa");
		promoAem.setPourcentReducAem(new BigDecimal(0.5));
		promoAem.setRaisonPromotionAem("Parce que c'�tait toujours pas assez bon march�");
		bgpa.majPromoAem(promoAem);
	}

	public void testGetPromoParc() {
		List<PromotionParc> promosParc = bgpa.getPromosParc();
		for (PromotionParc promo : promosParc) {
			System.out.println(promo.getNomPromotionParc() + "\t" + promo.getRaisonPromotionParc() + "\t" + promo.getDateDebutPromotionParc() + "\t" + promo.getDateFinPromotionParc() + "\t" + promo.getPourcentReducParc() + "\t" + promo.getProprietaire().getNomUtilisateur());
		}
	}

	public void testPromouvoirParc() {
		PromotionParc promoParc = new PromotionParc();
		promoParc.setDateDebutPromotionParc(new Date());
		promoParc.setDateFinPromotionParc(new Date());
		promoParc.setNomPromotionParc("Enorme promotion!");
		promoParc.setPourcentReducParc(new BigDecimal(0.7));
		Proprietaire prop = new Proprietaire();
		prop.setIdUtilisateur(3);
		promoParc.setProprietaire(prop);
		promoParc.setRaisonPromotionParc("J'ai que �a � faire!");
		bgpa.promouvoirParc(promoParc);
	}

	public void testMajPromoParc() {
		PromotionParc promoParc = new PromotionParc();
		promoParc.setIdPromotionParc(4);
		promoParc.setDateDebutPromotionParc(new Date());
		promoParc.setDateFinPromotionParc(new Date());
		promoParc.setNomPromotionParc("Promotion collossale!");
		promoParc.setPourcentReducParc(new BigDecimal(0.9));
		Proprietaire prop = new Proprietaire();
		prop.setIdUtilisateur(3);
		promoParc.setProprietaire(prop);
		promoParc.setRaisonPromotionParc("J'ai toujours rien d'autre � faire!");
		bgpa.majPromoParc(promoParc);
	}
}
